#include <iostream>
#include <algorithm>
using namespace std;

int way[110][110];
int dp[110][110];
int R, C;
int themax(int a,int b,int c,int d)
{
	return max(max(a, b), max(c, d));
}
int MaxLength(int i,int j)
{
	if (dp[i][j])
		return dp[i][j];
	int a = 0, b = 0, c = 0, d = 0;
	if(i-1>=0&&way[i][j]>way[i-1][j])
	{
		a = MaxLength(i - 1, j);
	}
	if(i+1<R&&way[i][j]>way[i+1][j])
	{
		b= MaxLength(i + 1, j);
	}
	if(j-1>=0&&way[i][j]>way[i][j-1])
	{
		c = MaxLength(i , j-1);
	}
	if(j+1<C&&way[i][j]>way[i][j+1])
	{
		d = MaxLength(i, j+1);
	}
	return dp[i][j] = themax(a, b, c, d) + 1;
}
int main()
{
	while (cin >> R >> C)
	{
		int tmax = 0;
		for (int i = 0; i < R; ++i)
		{
			for (int j = 0; j < C; ++j)
			{
				cin >> way[i][j];
				dp[i][j] = 0;
			}
		}
		for (int i = 0; i < R; ++i)
		{
			for (int j = 0; j < C; ++j)
			{				
				MaxLength(i, j);
			}
		}
		for (int i = 0; i < R; ++i)
		{
			tmax = max(tmax, *max_element(dp[i], dp[i] + C));
		}
		cout << tmax << endl;
	}
	return 0;
}

